gusucode.com > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM源码程序 > 支持向量机工具箱 - LIBSVM OSU_SVM LS_SVM\stprtool\svm\oaogilbert.m
function [model] = oaogilbert( data, labels, ker, arg, C, stop, tmax,verb) % OAOGILBERT One-Agains-One multi-class decomposition solved by Gilbert's alg. % % [model] = oaoksk( data, labels, ker, arg, C, stop, tmax, verb) % % Inputs: % data [dim x N] training patterns % labels [1 x N] labels of training patterns % ker [string] kernel, see 'help kernel'. % arg [...] argument of given kernel, see 'help kernel'. % C [real] trade-off between margin and training error. % stop [1 x 2] if stop(1) == 1 then stopping condition m*-m < stop(2) % is used else stopping condition (m*-m)/m < stop(2) is used. % Where m* is the optimial margin and m is the margin of found % hyperplane (in the given feature space). % tmax [int] maximal number of iterations. % verb [int] if 1 then progress info is displayed. % % Output: % model [struct] contains found O-A-O SVM classifier. % % Statistical Pattern Recognition Toolbox, Vojtech Franc, Vaclav Hlavac % (c) Czech Technical University Prague, http://cmp.felk.cvut.cz % Written Vojtech Franc (diploma thesis) 02.11.1999, 13.4.2000 % % Modifications % 3-Jun-2002, V.Franc [dim,num_data ] = size(data); num_classes = max(labels); model.name = 'One-Against-One, SVM classifier'; model.num_classes = num_classes; model.num_rules = num_classes*(num_classes-1)/2; model.rule = cell(model.num_rules); model.SVM.C = C; model.SVM.kernel = ker; model.SVM.arg = arg; model.trn_data = data; model.trn_labels = labels; model.kercnt=0; trn_errors = zeros(1, model.num_rules); sv=zeros(1,num_data); cnt=0; % builds num_classes*(num_classes-1)/2 1-a-1 classfication rules model.btime=cputime; for class1=1:num_classes-1, for class2=class1+1:num_classes, cnt=cnt+1; if verb ==1, fprintf(1, 'building rule %d-%d (%d of %d) ...', ... class1,class2, cnt, model.num_rules ); end model.rule{cnt}.class1 = class1; model.rule{cnt}.class2 = class2; % takes data from class1 and class2 model.rule{cnt}.data_inx = find(labels==class1 | labels==class2); model.rule{cnt}.labels = labels(model.rule{cnt}.data_inx); model.rule{cnt}.labels(find(model.rule{cnt}.labels==class1))=1; model.rule{cnt}.labels(find(model.rule{cnt}.labels==class2))=2; [Alpha,bias,sol,t,kercnt,margin,trnerr]=... kgilbert(data(:,model.rule{cnt}.data_inx),... model.rule{cnt}.labels,... stop,ker,arg,tmax,C); model.rule{cnt}.Alpha = Alpha; model.rule{cnt}.bias = bias; model.rule{cnt}.kercnt = kercnt; model.rule{cnt}.margin = margin; model.rule{cnt}.nsv = length(find(Alpha~=0)); model.rule{cnt}.trnerr = trnerr; model.kercnt = model.kercnt + kercnt; trn_errors(cnt) = trnerr; sv(model.rule{cnt}.data_inx(find(Alpha ~=0)))=1; if verb ==1, fprintf(1,'done\n'); end end end model.btime=cputime-model.btime; model.trnerr = mean( trn_errors); model.nsv = length(find(sv ~=0)); return; %EOF